package com.leonardo.persistenceme.model.persistancehandlers;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date;

public class DatePersistenceHandler extends PersistenceHandler {

	public void persist(Object obj, DataOutputStream stream) throws IOException {
		if(obj == null) {
			stream.writeLong(Long.MIN_VALUE);
			return;
		}
		long date = ((Date) obj).getTime();
		stream.writeLong(date);
	}

	public Object recover(DataInputStream stream) throws IOException {
		long date = stream.readLong();
		if(date == Long.MIN_VALUE)
			return null;
		return new Date(date);
	}

}
